<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" label-width="68px" style="margin-bottom: 10px">
      <el-row>
        <el-form-item label="客户名字" prop="kh">
          <el-input
            v-model="queryParams.kh"
            placeholder="请输入客户名字"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="下场时间">
          <el-date-picker
            v-model="querySj"
            @change="selectTime"
            value-format="yyyy-MM-dd HH:mm:ss"
            type="datetimerange"
            :default-time="['00:00:00', '23:59:59']"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            :picker-options="pickerOptions"
          >
          </el-date-picker>
        </el-form-item>
      </el-row>

      <el-row>
        <el-form-item label="总部编号" prop="dz">
          <el-input
            v-model="queryParams.zbbh"
            placeholder="请输入总部编号"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="报价单">
          <el-checkbox-group v-model="ywd" size="mini" @change="selectWszt">
            <el-checkbox border label="ws">完善</el-checkbox>
            <el-checkbox border label="dws">待完善</el-checkbox>
          </el-checkbox-group>
        </el-form-item>
        <el-form-item label="完工单">
          <el-checkbox-group v-model="wgd" size="mini" @change="selectWgdzt">
            <el-checkbox border label="ws">完善</el-checkbox>
            <el-checkbox border label="dlr">待录入</el-checkbox>
            <el-checkbox border label="dws">待完善</el-checkbox>
          </el-checkbox-group>
        </el-form-item>
        <el-form-item label="是否回款">
          <el-checkbox-group v-model="sfhk" size="mini" @change="selectSfhk">
            <el-checkbox border v-for="item in hkList" :label="item.dictValue">{{item.dictLabel}}</el-checkbox>
          </el-checkbox-group>
        </el-form-item>
      </el-row>

      <el-row v-if="showSearch">
        <el-form-item label="日期">
          <el-checkbox-group v-model="rq" size="mini" @change="selectRq">
            <el-checkbox label="zt" border>昨天</el-checkbox>
            <el-checkbox label="jt" border>今天</el-checkbox>
          </el-checkbox-group>
        </el-form-item>
        <el-form-item label="下场状态">
          <el-checkbox-group v-model="xczt" size="mini" @change="selectXczt">
            <el-checkbox border v-for="item in xcList" :label="item.dictValue">{{item.dictLabel}}</el-checkbox>
          </el-checkbox-group>
        </el-form-item>
      </el-row>

      <el-row>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="allQuery">高级查询</el-button>
        <el-button type="primary" icon="el-icon-d-caret" size="mini" @click="showSearch=!showSearch">{{showSearch ? "隐藏" : "展开"}}</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-row>
    </el-form>

    <Search v-if="showQuery" :show-search="showQuery" :param="queryParams" :sjztList="sjztList" :hkList="hkList" :sfList="xcList" @closeSearch="closeSearch" @search="search"></Search>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['gd:ywd:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdateData"
          v-hasPermi="['gd:ywd:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleQueryDelete"
          v-hasPermi="['gd:ywd:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['gd:ywd:export']"
        >全部导出</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          plain
          icon="el-icon-download"
          size="mini"
          :disabled="multiple"
          @click="handleSelectExport"
          v-hasPermi="['gd:ywd:export']"
        >导出选择数据</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="info"
          plain
          size="mini"
          :disabled="multiple"
          @click="downExcelData"
        >下载报价单</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="info"
          plain
          size="mini"
          :disabled="multiple"
          @click="downExcelData_Wgd"
        >下载完工单</el-button>
      </el-col>
      <el-col :span="1.5" v-if="this.$store.getters.name === 'admin'">
        <el-button
          type="success"
          plain
          size="mini"
          :disabled="multiple"
          @click="authData"
          v-hasPermi="['gd:ywd:export']"
        >授权选择数据</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
    <el-table v-loading="loading" :data="ywdList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column fixed label="总部编号" align="left" prop="zbbh" width="130">
        <template slot-scope="scope">
          <div style="color: #00afff;cursor: pointer;">
            <span @click="showInfo(scope.row)"> {{scope.row.zbbh}}</span> &nbsp;
            <el-link :underline="false" type="success" @click="copyText(scope.row.zbbh)" icon="el-icon-copy-document" style="font-size: 10px"></el-link>
          </div>
        </template>
      </el-table-column>
      <el-table-column fixed label="完工编号" align="left" prop="wgbh"width="130">
        <template slot-scope="scope">
          <div style="cursor: pointer;">
            <span v-if="scope.row.wgdList.length > 0"> {{scope.row.wgdList[0].wgbh}}</span> &nbsp;
            <el-link :underline="false" type="success" @click="copyText(scope.row.wgdList[0].wgbh)" icon="el-icon-copy-document" style="font-size: 10px"></el-link>
          </div>
        </template>
      </el-table-column>
<!--      <el-table-column label="客户编号" align="left" prop="bh" />-->
      <el-table-column fixed label="客户名字" align="left" prop="kh" width="200" />
<!--      <el-table-column label="地址" align="left" prop="dz"	 />-->
      <el-table-column label="检测方式" width="80" align="left" prop="jcfs" >
        <template slot-scope="scope">
          <span v-if="scope.row.jcfs==='2'">送检</span>
          <span v-else>下场</span>
        </template>
      </el-table-column>
      <el-table-column label="送检状态" align="center" prop="sjzt">
        <template slot-scope="scope">
          <span v-if="scope.row.sjzt==='1'"><el-tag type="warning">已送检</el-tag></span>
          <span v-else-if="scope.row.sjzt==='2'"><el-tag type="warning">已送回</el-tag></span>
        </template>
      </el-table-column>
      <el-table-column label="是否回款" align="center" prop="sfhk">
        <template slot-scope="scope">
          <span v-if="scope.row.sfhk==='1'"><el-tag type="success">是</el-tag></span>
          <span v-else-if="scope.row.sfhk==='2'"><el-tag type="warning">部分回款</el-tag></span>
          <span v-else-if="scope.row.sfhk==='3'"><el-tag type="warning">否</el-tag></span>
        </template>
      </el-table-column>
      <el-table-column label="回款金额" align="center" prop="hkje" width="75" />
      <el-table-column label="回款日期" align="center" prop="hksj" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.hksj, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="报价单" align="center" width="80">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.fj !== '' && scope.row.fj !== null && scope.row.fj !== undefined" type="success">完善</el-tag>
          <el-tag v-else type="warning">待完善</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="完工单" align="center" width="80">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.wgdList.length > 0
                  && scope.row.wgdList[0].fj !== ''
                  && scope.row.wgdList[0].fj !== null
                  && scope.row.wgdList[0].fj !== undefined" type="success">完善</el-tag>
          <el-tooltip content="点击完善" placement="right" effect="light">
            <el-tag
              v-if="scope.row.wgdList.length === 0"
              style="cursor: pointer"
              type="warning"
              @click="wsWgd(scope.row)">待录入</el-tag>
          </el-tooltip>
          <el-tooltip content="点击完善" placement="right" effect="light">
            <el-tag
              v-if="scope.row.wgdList.length > 0
                  && (scope.row.wgdList[0].fj === ''
                  || scope.row.wgdList[0].fj === null
                  || scope.row.wgdList[0].fj === undefined)"
              style="cursor: pointer"
              type="warning"
              @click="wsWgd(scope.row)">待完善</el-tag>
          </el-tooltip>
        </template>
      </el-table-column>
      <el-table-column label="下场时间" align="center" prop="xcsj" width="100">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.xcsj, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="是否已下场" width="110" align="center" prop="sfyxc">
        <template slot-scope="scope">
          <!--          <span v-if="scope.row.sfyxc==='1'">待安排</span>-->
          <!--          <span v-else-if="scope.row.sfyxc==='2'">已安排待下场</span>-->
          <!--          <span v-else-if="scope.row.sfyxc==='3'">已下场</span>-->
          <span>{{xcList.filter(item => item.dictValue === scope.row.sfyxc)[0] !== undefined ? xcList.filter(item => item.dictValue === scope.row.sfyxc)[0].dictLabel : ""}}</span>
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="bz" width="200" show-overflow-tooltip />
      <el-table-column fixed="right" label="操作" align="center" width="120" class-name="small-padding fixed-width">
        <template slot-scope="scope">
<!--          v-if="updateDelAuth(scope.row.status)"-->
<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-tickets"-->
<!--            @click="scWgd(scope.row)"-->
<!--          >生成完工单</el-button>-->
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['gd:ywd:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['gd:ywd:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改业务单对话框 -->
    <el-dialog :title="title" :visible.sync="open" @close="cancel" width="80%" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="总部编号" prop="zbbh">
              <el-input v-model="form.zbbh" placeholder="请输入总部编号" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="客户名称" prop="kh">
              <el-input v-model="form.kh" placeholder="请选择客户">
                <el-button type="primary" slot="prepend" @click.native="selectUser"> 选择客户 </el-button>
              </el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="地址" prop="dz">
              <el-input
                type="textarea"
                placeholder="请输入地址"
                v-model="form.dz">
              </el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="附件" prop="fj">
              <el-upload
                ref="upload"
                class="upload-demo"
                :action="src"
                :on-success="handleSuccess"
                :on-error="handleError"
                :before-remove="handleRemove"
                :headers="uploadHeaders"
                accept=".xlsx, .xls"
                multiple
                :limit="1"
                :file-list="fjList"
                :on-exceed="handleExceed"
                :on-preview="handlePreview"
              >
                <el-button size="small" type="primary"> <i class="el-icon-upload"></i> 点击上传</el-button>
                <div slot="tip" class="el-upload__tip">只能上传Excel文件</div>
              </el-upload>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="检测方式" prop="jcfs">
                <el-radio-group v-model="form.jcfs">
                <el-radio :label="'1'" border>下场</el-radio>
                <el-radio :label="'2'" border>送检</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col v-if="form.jcfs === '2'" :span="12">
            <el-form-item label="送检状态" :rules="form.jcfs === '2'? { required: true, message: '请选择送检状态'} : { required: false}">
              <el-select v-model="form.sjzt" style="width: 100%;" placeholder="请选择">
                <el-option
                  v-for="item in sjztList"
                  :key="item.dictValue"
                  :label="item.dictLabel"
                  :value="item.dictValue">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row v-if="form.jcfs === '2'">
          <el-col :span="12">
            <el-form-item label="送检时间" prop="sjsj" :rules="form.sjzt === '1'? { required: true, message: '请选择送检时间'} : { required: false}">
              <el-date-picker clearable
                              style="width: 100%"
                              v-model="form.sjsj"
                              type="datetime"
                              default-time="08:00:00"
                              value-format="yyyy-MM-dd HH:mm:ss"
                              placeholder="请选择送检时间">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="送回时间" prop="shsj" :rules="form.sjzt === '2'? { required: true, message: '请选择送回时间'} : { required: false}">
              <el-date-picker clearable
                              style="width: 100%"
                              v-model="form.shsj"
                              default-time="08:00:00"
                              type="datetime"
                              value-format="yyyy-MM-dd HH:mm:ss"
                              placeholder="请选择送回时间">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row v-if="form.jcfs === '1'">
          <el-col :span="12">
            <el-form-item label="是否已下场" prop="sfyxc">
              <el-select v-model="form.sfyxc" style="width: 100%;" placeholder="请选择">
                <el-option
                  v-for="item in xcList"
                  :key="item.dictValue"
                  :label="item.dictLabel"
                  :value="item.dictValue">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="下场时间" prop="xcsj">
              <el-date-picker clearable
                              style="width: 100%"
                              v-model="form.xcsj"
                              type="datetime"
                              default-time="08:00:00"
                              @change="changeData"
                              value-format="yyyy-MM-dd HH:mm:ss"
                              placeholder="请选择下场时间">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="是否回款" prop="sfhk">
              <el-select v-model="form.sfhk" style="width: 100%;" placeholder="请选择">
                <el-option
                  v-for="item in hkList"
                  :key="item.dictValue"
                  :label="item.dictLabel"
                  :value="item.dictValue">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="回款金额" prop="hkje">
              <el-input v-model="form.hkje" placeholder="请输入回款金额" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="回款日期" prop="hksj">
              <el-date-picker clearable
                              style="width: 100%"
                              v-model="form.hksj"
                              type="date"
                              default-time="08:00:00"
                              value-format="yyyy-MM-dd"
                              placeholder="请选择回款时间">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="合同金额" prop="htje">
              <el-input v-model="form.htje" placeholder="请输入合同金额" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="下场负责人">
<!--              <el-input v-model="form.xcfzrname" readonly />-->
              <el-input v-model="form.xcfzrname" readonly placeholder="请选择下场负责人">
                <el-button type="primary" slot="prepend" @click.native="selectXcry"> 选择下场负责人 </el-button>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="下场人员">
<!--              <el-input v-model="form.xcryname" readonly />-->
              <el-input v-model="form.xcryname" readonly placeholder="请选择下场人员">
                <el-button type="primary" slot="prepend" @click.native="selectXcry"> 选择下场人员 </el-button>
              </el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="录单人" prop="createBy">
              <el-input v-model="form.createBy" readonly />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="录单时间" prop="createTime">
              <el-input v-model="form.createTime" readonly />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="备注" prop="bz">
              <el-input
                maxlength="1000"
                :autosize="{ minRows: 3, maxRows: 4 }"
                show-word-limit
                type="textarea"
                placeholder="请输入内容"
                v-model="form.bz">
              </el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button v-if="ShowBtn" :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
      <khList v-if="showUser" :showUser="showUser" @selectData="selectData" @closeDialog="closeDialog"></khList>
      <!-- 预览组件 -->
      <PdfPreView
        v-if="showPdf"
        :showPdf="showPdf"
        :fjId="fjId"
        :title="fjTitle"
        @cancel="cancelPdf"
      ></PdfPreView>
      <!-- 选择下场人员 -->
      <xcForm
        v-if="showUserDialog"
        :showSelectUser="showUserDialog"
        :form="xcData"
        @close="closeUser"
        @xcryData="xcryData"
      ></xcForm>
    </el-dialog>

    <!-- 生成完工单 -->
    <el-dialog title="生成完工单" :visible.sync="showGenWgd" @close="cancelWgd" width="70%" append-to-body>
      <el-form ref="bjdForm" :model="wgdForm" :rules="rulesBjd" label-width="80px">
        <el-row>
          <el-col :span="24">
            <el-form-item label="报价日期" prop="bjrq">
              <el-date-picker clearable
                              style="width: 100%"
                              v-model="wgdForm.bjrq"
                              type="date"
                              value-format="yyyy-MM-dd"
                              placeholder="请选择报价日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label-width="330px" label="生成的报价单编号是出厂编号 还是 管理编号数据"></el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="编号" prop="bjbh">
              <el-radio v-model="wgdForm.bjbh" label="ccbh" border size="medium">出厂编号</el-radio>
              <el-radio v-model="wgdForm.bjbh" label="glbh" border size="medium">管理编号</el-radio>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
<!--        <el-button :loading="buttonLoading" type="primary" @click="shengChengBjd">确 定</el-button>-->
<!--        <el-button type="primary" @click="queryLsBjd">查看历史报价单</el-button>-->
<!--        <el-button @click="cancelBjd">取 消</el-button>-->
      </div>

    </el-dialog>

    <!-- 完工单详情 -->
    <wgdForm v-if="openWgd" :showForm="openWgd" :title="wgdTitle" :formInfo="wgdData" :ShowBtn="true" @close="cancelWgdInfo"></wgdForm>

  </div>
</template>

<script>
import xcForm from '@/views/gd/xcap/xcForm.vue'
import khList from "@/views/gd/ywd/khList.vue";
import PdfPreView from '@/views/components/componse/PdfView.vue'
import Search from '@/views/gd/ywd/Search.vue'
import wgdForm from "@/views/gd/wgd/formInfo.vue"
import { listYwd, getYwd, delYwd, addYwd, updateYwd, authDatas, querySyList, downExcel } from '@/api/gd/ywd'
import { getWgdByZbbh } from "@/api/gd/wgd";
import { delFj, getFj, getFjById } from '@/api/gd/fj'
import { getToken } from '@/utils/auth'
import { parseTime } from '@/utils/ruoyi'
import { getKhxx } from '@/api/gd/khxx'
import { downLoadZip } from '@/api/zipdownload'

export default {
  name: "Ywd",
  components: { khList, PdfPreView, Search, xcForm, wgdForm },
  data() {
    return {
      openWgd: false,
      wgdTitle: "",
      wgdData: {},
      rq: [],
      showUserDialog: false,
      xcData: {},
      userName: this.$store.getters.name,
      // src: '/dev-api/gd/fj/file/upload',
      src: this.uploadSrc + '/gd/fj/file/upload',
      ShowBtn: true,
      showPdf: false,
      fjTitle: "",
      fjId: "",
      uploadHeaders: { 'Authorization': 'Bearer ' + getToken() }, // 如果需要CSRF保护的话
      fjList: [],
      showUser: false,
      // 按钮loading
      buttonLoading: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: false,
      showQuery: false,
      // 总条数
      total: 0,
      // 业务单表格数据
      ywdList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      sfhk: [],
      xczt: [],
      ywd: [],
      wgd: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        zbbh: undefined,
        kh: undefined,
        dz: undefined,
        fj: undefined,
        fjpdf: undefined,
        xcsj: undefined,
        sfyxc: undefined,
        sfhk: undefined,
        hkje: undefined,
        hksj: undefined,
        bz: undefined,
        createTime: undefined,
        startXcsj: undefined,
        endXcsj: undefined,
        xcpx: false,
        syWgdzt: undefined,
        params: {
          startTime: '',
          endTime: '',
          wszt: '',
          wgdzt: ''
        }
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        id: [
          { required: true, message: "id不能为空", trigger: "blur" }
        ],
        zbbh: [
          { required: true, message: "总部编号不能为空", trigger: "blur" }
        ],
        kh: [
          { required: true, message: "客户不能为空", trigger: "change" }
        ],
        dz: [
          { required: true, message: "地址不能为空", trigger: "change" }
        ],
        sfyxc: [
          { required: true, message: "是否已下场不能为空", trigger: "blur" }
        ],
        sfhk: [
          { required: true, message: "是否回款不能为空", trigger: "blur" }
        ],
        htje: [
          { required: true, message: "合同金额不能为空", trigger: "blur" }
        ],
        jcfs: [
          { required: true, message: "请选择检测类型", trigger: "blur" }
        ]
      },
      xcList: [],
      hkList: [],
      sjztList: [],
      querySj: [],
      showXcry: false,
      pickerOptions: {
        shortcuts: [{
          text: '最近一周',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '最近一个月',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '最近三个月',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
            picker.$emit('pick', [start, end]);
          }
        }]
      },
      showGenWgd: false,
      wgdForm: {},
      // 报价单表单校验
      rulesBjd: {
        bjrq: [
          { required: true, message: "请选择报价日期", trigger: "blur" }
        ],
        bjbh: [
          { required: true, message: "请选择编号", trigger: "blur" }
        ]
      },
      sy: false
    };
  },
  created() {
    if (!this.sy) {
      this.getList();
    }
    this.getDict();
  },
  watch: {
    '$route': {
      immediate: true,
      async handler(route) {
        if (route.query.sy === "true") {
          await this.resetData()
          switch (route.query.type) {
            case "dlrwgdjt":  // 录入今天
              await this.handleData(route.query.type)
              this.queryParams.params.wgdzt = "dlr"
              this.wgd.push("dlr")
              break
            case "dwswgdjt":  // 待完善今天
              await this.handleData(route.query.type)
              this.queryParams.params.wgdzt = "dws"
              this.wgd.push("dws")
              break
            case "dlrwgdzdy":  // 待录入完工单自定义
              await this.handleData(route.query.type)
              this.queryParams.params.wgdzt = "dlr"
              this.wgd.push("dlr")
              break
            case "dwswgdzdy":  // 待完善完工单自定义
              await this.handleData(route.query.type)
              this.queryParams.params.wgdzt = "dws"
              this.wgd.push("dws")
              break
          }
          this.queryParams.pageSize = 10
          console.log("this.queryParams", this.queryParams)
          this.sy = true
          this.getList()
        }
      },
      deep: true
    },
  },
  methods: {
    async handleData(type) {
      const now = new Date();
      // 判断是今天还是自定义
      if (type === 'dlrwgdjt' || type === 'dwswgdjt') {
        // 当前年的1号0点
        const year = now.getFullYear();
        const firstDayOfYear = new Date(year, 0, 1, 0, 0, 0, 0);
        let startTime = this.formatDateTime(firstDayOfYear);
        // 设置时间为今天的 23 点 59 分 59 秒
        const startOfDay = new Date(now.getFullYear(), now.getMonth(), now.getDate());
        const endOfDay = new Date(startOfDay);
        endOfDay.setHours(23, 59, 59, 999);
        let endTime = this.formatDateTime(endOfDay);
        this.queryParams.params.startTime = startTime
        this.queryParams.params.endTime = endTime
        this.$set(this.querySj, 0 , startTime)
        this.$set(this.querySj, 1 , endTime)
      }else if (type === 'dlrwgdzdy' || type === 'dwswgdzdy') {
        const year = now.getFullYear();
        // 当前年的1号0点
        const firstDayOfYear = new Date(year, 0, 1, 0, 0, 0, 0);
        let startTime = this.formatDateTime(firstDayOfYear);
        // 当前时间三天前的时间23:59:59
        let dayNum = 3
        await this.getConfigKey("sy_dzwgdcx").then(async res => {
          dayNum = res.msg
        })
        const threeDaysAgo = new Date(now.getTime() - (dayNum * 24 * 60 * 60 * 1000));
        threeDaysAgo.setHours(23, 59, 59, 999);
        let endTime = this.formatDateTime(threeDaysAgo);
        this.queryParams.params.startTime = startTime
        this.queryParams.params.endTime = endTime
        this.$set(this.querySj, 0 , startTime)
        this.$set(this.querySj, 1 , endTime)
      }

    },
    formatDateTime(date) {
      const year = date.getFullYear();
      const month = String(date.getMonth() + 1).padStart(2, '0');
      const day = String(date.getDate()).padStart(2, '0');
      const hours = String(date.getHours()).padStart(2, '0');
      const minutes = String(date.getMinutes()).padStart(2, '0');
      const seconds = String(date.getSeconds()).padStart(2, '0');
      return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
    },
    // 判断完工单完善状态
    pdWgdWszt(row) {
      let result = false
      if(row.wgdList.length > 0 && row.wgdList[0].fj !== '' && row.wgdList[0].fj !== null && row.wgdList[0].fj !== undefined) {
        result = true
      }
      return result
    },
    // 完善完工单
    wsWgd(row) {
      // 通过总部编号查询完工单
      if (row.zbbh !== '' && row.zbbh!== null && row.zbbh !== undefined) {
        getWgdByZbbh(row.zbbh).then(res => {
          console.log("res.data", res.data)
          if (res.data === null) {  // 如果等于 null 则新增
            this.resetWgd(row)
            this.openWgd = true
            this.wgdTitle = "添加完工单"
          }else {  // 否则就修改
            this.openWgd = true
            this.wgdTitle = "修改完工单"
            this.wgdData = res.data
          }
        })
      }else {
        this.$message.error("请完善总部编号")
      }

    },
    async resetWgd(row) {
      this.$set(this.wgdData, 'zbbh', row.zbbh)
      this.$set(this.wgdData, 'createBy', this.$store.getters.nickName)
      this.$set(this.wgdData, 'createTime', new Date())
      this.$set(this.wgdData, 'sfykfp', "N")
      // 通过客户id查询一下当前的客户信息
      if (row.khid !== '' && row.khid !== null && row.khid !== undefined) {
        getKhxx(row.khid).then(res => {
          this.$set(this.wgdData, 'khname', res.data.khname)
          this.$set(this.wgdData, 'dh', res.data.dh)
          this.$set(this.wgdData, 'dz', res.data.dz)
          this.$set(this.wgdData, 'xhkh', res.data.xhkh)
          this.$set(this.wgdData, 'sh', res.data.sh)
          this.$set(this.wgdData, 'bh', res.data.bh)
        })
      }else {
        this.$set(this.wgdData, 'kh', row.khname)
        this.$set(this.wgdData, 'bh', row.bh)
        this.$set(this.wgdData, 'dz', row.dz)
      }
    },
    cancelWgdInfo() {
      this.openWgd = false
      this.wgdData = {}
      this.getList()
    },
    // 生成完工单
    scWgd(row) {
      if (row.fj !== '' && row.fj !== undefined && row.fj !== null) {
        this.$set(this, 'wgdForm', row)
        // this.$set(this.wgdForm, 'bjrq', new Date())
        this.showGenWgd = true
      }else {
        this.$message.error("请先上传业务单附件！")
      }
    },
    cancelWgd() {
      this.wgdForm = {}
      this.showGenWgd = false
    },
    xcryData(row) {
      this.showUserDialog = false
    },
    closeUser() {
      this.xcData = {}
      this.showUserDialog = false
      this.getList()
    },
    selectXcry() {
      this.xcData = this.form
      this.showUserDialog = true
    },
    changeData(time) {
      console.log("time", time)
    },
    selectTime(time) {
      if(time !== null) {
        this.queryParams.params.startTime = time[0]
        this.queryParams.params.endTime = time[1]
      }
    },
    defaultTime() {
      const now = new Date();
      now.setHours(8, 0, 0, 0);
      return now
    },
    updateDelAuth(status) {
      return this.userName === 'admin' || status === '1'
    },
    getDict() {
      // 是否已下场
      this.getDicts("gd_xczt").then(res => {
        this.xcList = res.data
      })
      // 是否回款
      this.getDicts("gd_sfhk").then(res => {
        this.hkList = res.data
      })
      // 送检状态
      this.getDicts("gd_sjzt").then(res => {
        this.sjztList = res.data
      })
    },
    // ======  上传开始  ======
    handleSuccess(response, file) {
      if (this.ShowBtn) {
        // 更新状态或者通知用户上传成功
        this.$message.success('上传成功');
        // 上传成功以后，将id设置
        this.form.fj = response.fj
        this.form.fjpdf = response.fjpdf
        if (this.form.id !== undefined) {
          updateYwd(this.form).then(objs => {
            getYwd(this.form.id).then(async response => {
              this.fjList = []
              let obj = response.data
              if (obj.fjpdf !== "" && obj.fjpdf !== null && obj.fjpdf !== undefined) {
                await getFj(obj.fjpdf).then(res => {
                  if (res.data !== null) {
                    const data = {
                      fjid: res.data.fjid,
                      name: res.data.fjname,
                      path: res.data.fjpath
                    }
                    this.fjList.push(data)
                  }
                })
              }
              if (obj.fj !== "" && obj.fj !== null && obj.fj !== undefined) {
                await getFj(obj.fj).then(res => {
                  if (res.data !== null) {
                    const data = {
                      fjid: res.data.fjid,
                      name: res.data.fjname,
                      path: res.data.fjpath
                    }
                    this.fjList.push(data)
                  }
                })
              }
            })
          })
        }
      }else {
        this.fjList = []
        this.$message.error("当前是预览模式，禁止上传")
      }
    },
    // 上传失败回调
    handleError(err, file) {
      // 处理错误并通知用户
      this.$message.error('上传失败：', err);
      this.fjList = []
    },
    // 删除回调
    handleRemove(file, fileList) {
      // 判断当前的状态是否是预览状态，如果是预览状态，则不可以删除
      if (this.ShowBtn) {
        this.$modal.confirm('请确认是否删除附件名称为：'+file.name+' 的数据?').then(() => {
          // 调用删除附件功能，将附件进行删除
          let fjId = []
          fjId.push(file.id || file.fjid)
          let ids = []
          fileList.forEach(item => {
            ids.push(item.fjid)
          })
          ids.push(file.fjid)
          delFj(fjId).then(res => {
            if (res.code === 200) {
              this.$message.success("删除成功！")
              // 删除后更新数据
              if (ids !== '' && ids !== null) {
                this.form.fj = ""
                this.form.fjpdf = ""
                updateYwd(this.form).then(objs => {
                  getYwd(this.form.id).then(async response => {
                    this.fjList = []
                    // fileList = []
                    let obj = response.data
                    if (obj.fjpdf !== "" && obj.fjpdf !== null && obj.fjpdf !== undefined) {
                      await getFj(obj.fjpdf).then(res => {
                        if (res.data !== null) {
                          const data = {
                            fjid: res.data.fjid,
                            name: res.data.fjname,
                            path: res.data.fjpath
                          }
                          this.fjList.push(data)
                          // fileList.push(data)
                        }
                      })
                    }
                    if (obj.fj !== "" && obj.fj !== null && obj.fj !== undefined) {
                      await getFj(obj.fj).then(res => {
                        if (res.data !== null) {
                          const data = {
                            fjid: res.data.fjid,
                            name: res.data.fjname,
                            path: res.data.fjpath
                          }
                          // fileList.push(data)
                          this.fjList.push(data)
                        }
                      })
                    }
                  })
                })
              }
            }
          })
        }).catch(() => {
          fileList.push(file)
        })

      }else {
        this.$message.error("当前是预览状态，禁止删除")
      }

    },
    handleExceed(files, fileList) {
      this.$message.warning(`当前限制选择 1 个文件，本次选择了 ${files.length} 个文件`);
    },
    // 文件点击回调
    handlePreview(file) {
      let suffix = file.name.substring(file.name.lastIndexOf(".") + 1);
      if (suffix === 'pdf') {
        this.showPdf = true
        this.fjId = file.fjid
        this.fjTitle = "PDF预览"
      }else if (suffix === 'xlsx' || suffix === 'xls') {
        let id = file.fjid || file.response.fj
        getFjById(id, 'blob').then(response => {
          const binaryData = [];
          binaryData.push(response);
          let url = window.URL.createObjectURL(new Blob(binaryData, { type: 'application/octet-stream' }));
          const link = document.createElement('a');
          link.href = url
          link.download = file.name;
          document.body.appendChild(link);
          link.click();
          document.body.removeChild(link);
        })
      }

    },
    cancelPdf() {
      this.showPdf = false
    },
    // ======  上传结束  ====
    copyText(data) {
      const textarea = document.createElement('textarea');
      textarea.value = data;
      document.body.appendChild(textarea);
      textarea.select();
      try {
        // 尝试执行复制操作
        const success = document.execCommand('copy');
        if (success) {
          this.$message.success("已复制！")
        } else {
          this.$message.error("复制失败！")
        }
      } catch (error) {
        this.$message.error("复制失败！")
      }
      document.body.removeChild(textarea);
    },
    showInfo(row) {
      this.form = row
      getYwd(row.id).then(response => {
        let obj = response.data
        if (obj.fj !== "" && obj.fj !== null && obj.fj !== undefined) {
          getFj(obj.fj).then(res => {
            if (res.data !== null) {
              const data = {
                fjid: res.data.fjid,
                name: res.data.fjname,
                path: res.data.fjpath
              }
              this.fjList.push(data)
            }
          })
        }
        if (obj.fjpdf !== "" && obj.fjpdf !== null && obj.fjpdf !== undefined) {
          getFj(obj.fjpdf).then(res => {
            if (res.data !== null) {
              const data = {
                fjid: res.data.fjid,
                name: res.data.fjname,
                path: res.data.fjpath
              }
              this.fjList.push(data)
            }
          })
        }
        this.open = true
        this.ShowBtn = false
        this.title = "业务单信息";
      })

    },
    closeDialog() {
      this.showUser = false
    },
    selectData(row) {
      this.form.kh = row.khname
      this.form.khid = row.id
      this.form.dz = row.dz
      this.form.dh = row.dh
      this.form.bh = row.bh
      this.closeDialog()
    },
    selectUser() {
      this.showUser = true
    },
    /** 查询业务单列表 */
    getList() {
      this.loading = true;
      listYwd(this.queryParams, 'ywd').then(response => {
        this.ywdList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.ShowBtn = true
      this.fjList = []
      this.getList()
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        zbbh: undefined,
        kh: undefined,
        dz: undefined,
        fj: undefined,
        fjpdf: undefined,
        xcsj: '',
        sfyxc: "1",
        sfhk: "3",
        jcfs: "1",
        hkje: undefined,
        hksj: undefined,
        bz: undefined,
        createBy: this.$store.getters.name,
        createTime: parseTime(new Date()),
        updateBy: undefined,
        updateTime: undefined
      };
      this.queryParams = {
        pageNum: 1,
        pageSize: 10,
        zbbh: undefined,
        kh: undefined,
        dz: undefined,
        fj: undefined,
        fjpdf: undefined,
        xcsj: undefined,
        sfyxc: undefined,
        sfhk: undefined,
        hkje: undefined,
        hksj: undefined,
        bz: undefined,
        xcpx: false,
        params: {
          startTime: '',
          endTime: ''
        }
      }
      this.resetForm("form");
    },
    allQuery() {
      this.showQuery = true
    },
    closeSearch() {
      this.queryParams = {}
      this.showQuery = false
      this.getList()
    },
    search(query) {
      this.queryParams = query
      this.showQuery = false
      this.getList()
    },
    selectSfhk(val) {
      this.queryParams.sfhk = val.toString()
      this.getList()
    },
    selectXczt(val) {
      this.queryParams.sfyxc = val.toString()
      this.getList()
    },
    selectWszt(val) {
      this.queryParams.params.wszt = val.toString()
      this.getList()
    },
    selectWgdzt(val) {
      this.queryParams.params.wgdzt = val.toString()
      this.getList()
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    resetData() {
      this.resetForm("queryForm");
      this.queryParams = {
        pageNum: 1,
        pageSize: 10,
        zbbh: undefined,
        kh: undefined,
        dz: undefined,
        fj: undefined,
        fjpdf: undefined,
        xcsj: undefined,
        sfyxc: undefined,
        sfhk: undefined,
        hkje: undefined,
        hksj: undefined,
        bz: undefined,
        createTime: undefined,
        startXcsj: undefined,
        endXcsj: undefined,
        xcpx: false,
        syWgdzt: undefined,
        params: {
          startTime: '',
          endTime: '',
          wszt: ''
        }
      }
      this.querySj = []
      this.sfhk = []
      this.ywd = []
      this.wgd = []
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.queryParams = {
          pageNum: 1,
          pageSize: 10,
          zbbh: undefined,
          kh: undefined,
          dz: undefined,
          fj: undefined,
          fjpdf: undefined,
          xcsj: undefined,
          sfyxc: undefined,
          sfhk: undefined,
          hkje: undefined,
          hksj: undefined,
          bz: undefined,
          xcpx: false,
          params: {
            startTime: '',
            endTime: ''
        }
      }
      this.querySj = []
      this.sfhk = []
      this.ywd = []
      this.wgd = []
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加业务单";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.loading = true;
      this.reset();
      const id = row.id || this.ids
      getYwd(id).then(response => {
        if (response.data.fj !== "" && response.data.fj !== null && response.data.fj !== undefined) {
          getFj(response.data.fj).then(res => {
            if (res !== null && res.data !== null) {
              const obj = {
                fjid: res.data.fjid,
                name: res.data.fjname,
                path: res.data.fjpath
              }
              this.fjList.push(obj)
            }
          })
        }
        if (response.data.fjpdf !== "" && response.data.fjpdf !== null && response.data.fjpdf !== undefined) {
          getFj(response.data.fjpdf).then(res => {
            if (res !== null && res.data !== null) {
              const obj = {
                fjid: res.data.fjid,
                name: res.data.fjname,
                path: res.data.fjpath
              }
              this.fjList.push(obj)
            }
          })
        }
        this.loading = false;
        this.form = response.data;
        this.open = true;
        this.title = "修改业务单";
      });
    },
    handleUpdateData() {
      this.loading = true;
      this.reset();
      const ids = this.ids
      getYwd(ids).then(response => {
        if (response.data.fj !== "" && response.data.fj !== null && response.data.fj !== undefined) {
          getFj(response.data.fj).then(res => {
            if (res !== null && res.data !== null) {
              const obj = {
                fjid: res.data.fjid,
                name: res.data.fjname,
                path: res.data.fjpath
              }
              this.fjList.push(obj)
            }
          })
        }
        if (response.data.fjpdf !== "" && response.data.fjpdf !== null && response.data.fjpdf !== undefined) {
          getFj(response.data.fjpdf).then(res => {
            if (res !== null && res.data !== null) {
              const obj = {
                fjid: res.data.fjid,
                name: res.data.fjname,
                path: res.data.fjpath
              }
              this.fjList.push(obj)
            }
          })
        }
        this.loading = false;
        this.form = response.data;
        this.open = true;
        this.title = "修改业务单";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.buttonLoading = true;
          this.form.status = '0'
          if (this.form.id != null) {
            updateYwd(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            }).finally(() => {
              this.buttonLoading = false;
            });
          } else {
            addYwd(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            }).finally(() => {
              this.buttonLoading = false;
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id
      this.$modal.confirm('请确认是否删除编号为： ' + row.zbbh + ' 客户为： ' + row.kh + ' 的数据?').then(() => {
        this.loading = true;
        return delYwd(ids);
      }).then(() => {
        this.loading = false;
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      }).finally(() => {
        this.loading = false;
      });
    },
    // 批量删除数据
    handleQueryDelete() {
      const ids = this.ids;
      const data = this.ywdList.filter(item => ids.some(id => id === item.id))
      let obj = ""
      data.forEach((item, index) => {
        if (index === data.length-1) {
          obj += "编号为：" + item.zbbh + " 客户为： " + item.kh
        }else {
          obj += "编号为："  + item.zbbh + " 客户为： " + item.kh + "， "
        }
      })
      this.$modal.confirm('请确认是否删除 ' + obj + ' 的数据?').then(() => {
        this.loading = true;
        return delYwd(ids);
      }).then(() => {
        this.loading = false;
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      }).finally(() => {
        this.loading = false;
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      let name = this.getTodayDate()
      this.download('gd/ywd/export/ywd', {
        ...this.queryParams
      }, `${name}  业务单_${new Date().getTime()}.xlsx`)
    },
    // 导出选择数据
    handleSelectExport() {
      const ids = this.ids;
      let name = this.getTodayDate()
      this.download('gd/ywd/exportSelectDat/' + ids, {
        ...this.queryParams
      }, `${name} 业务单_${new Date().getTime()}.xlsx`)
    },
    getTodayDate() {
      const date = new Date();
      const year = date.getFullYear();
      const month = ('0' + (date.getMonth() + 1)).slice(-2);
      const day = ('0' + date.getDate()).slice(-2);
      return `${year}${month}${day}`;
    },
    authData() {
      const ids = this.ids;
      const data = this.ywdList.filter(item => ids.some(id => id === item.id))
      let obj = ""
      data.forEach((item, index) => {
        if (index === data.length-1) {
          obj += "编号为：" + item.zbbh + " 客户为： " + item.kh
        }else {
          obj += "编号为："  + item.zbbh + " 客户为： " + item.kh + "， "
        }
      })
      this.$modal.confirm('请确认是否要给 ' + obj+' 客户授权').then(() => {
        this.loading = true;
        return authDatas(ids);
      }).then(() => {
        this.loading = false;
        this.getList();
        this.$modal.msgSuccess("授权成功！");
      }).catch(() => {
      }).finally(() => {
        this.loading = false;
      });
    },
    // 下载Excel
    downExcelData() {
      const ids = this.ids;
      const data = this.ywdList.filter(item => ids.some(id => id === item.id))
      let obj = ""
      for (let i = 0; i < data.length; i++) {
        let item = data[i]
        if (obj.length > 200) {
          obj += "..."
          break
        }else {
          if (i === data.length-1) {
            obj += "编号为：" +item.zbbh + " 客户为： " + item.kh
          }else {
            obj += "编号为：" +item.zbbh + " 客户为： " + item.kh + ", "
          }
        }
      }
      this.$modal.confirm('请确认是否要下载 ' + obj+' 业务单的Excel').then(() => {
        this.loading = true;
        downLoadZip('/gd/ywd/downExcel', "业务单_"+this.getFileDownName() , ids.toString())
      }).finally(() => {
        this.loading = false;
        this.getList();
      });
    },
    downExcelData_Wgd() {
      const ids = this.ids;
      const data = this.ywdList.filter(item => ids.some(id => id === item.id))
      let obj = ""
      for (let i = 0; i < data.length; i++) {
        let item = data[i]
        if (obj.length > 200) {
          obj += "..."
          break
        }else {
          if (i === data.length-1) {
            obj += "编号为：" +item.zbbh + " 客户为： " + item.kh
          }else {
            obj += "编号为：" +item.zbbh + " 客户为： " + item.kh + ", "
          }
        }
      }
      this.$modal.confirm('请确认是否要下载 ' + obj+' 业务单的Excel').then(() => {
        this.loading = true;
        downLoadZip('/gd/ywd/downExcel/wgd', "完工单_"+this.getFileDownName() , ids.toString())
      }).finally(() => {
        this.loading = false;
        this.getList();
      });
    },
    getFileDownName() {
      let date = new Date()
      const year = date.getFullYear();
      const month = ('0' + (date.getMonth() + 1)).slice(-2);
      const day = ('0' + date.getDate()).slice(-2);
      const hours = ('0' + date.getHours()).slice(-2);
      const minutes = ('0' + date.getMinutes()).slice(-2);
      const seconds = ('0' + date.getSeconds()).slice(-2);
      return `${year}${month}${day}${hours}${minutes}${seconds}`;
    },
    selectRq(item) {
      if (item.length > 0) {
        let hasZt = item.some(item => item === 'zt');
        let hasJt = item.some(item => item === 'jt');
        // ===== 获取昨天日期
        let date = new Date()
        const yesterday = new Date(date);
        yesterday.setDate(yesterday.getDate() - 1); // 减去一天得到昨天的日期
        let zt = this.formatDate(yesterday);
        // ==== 获取今天日期
        let jt = this.formatDate(date);
        // 判断昨天和今天是否已经勾选
        if (hasZt && hasJt) {
          this.queryParams.startCreateTime = zt + " 00:00:00"
          this.queryParams.endCreateTime = jt + " 23:59:59"
        }else if (hasZt) {
          // 如果只有昨天
          this.queryParams.startCreateTime = zt + " 00:00:00"
          this.queryParams.endCreateTime = zt + " 23:59:59"
        }else if (hasJt) {
          this.queryParams.startCreateTime = jt + " 00:00:00"
          this.queryParams.endCreateTime = jt + " 23:59:59"
        }
      }else {
        this.queryParams.startCreateTime = ""
        this.queryParams.endCreateTime = ""
      }
      this.getList()
    },
    selectDay(item) {
      // 1.昨天 2.今天 3.明天
      let date = new Date()
      if (item === 1) {
        const yesterday = new Date(date);
        yesterday.setDate(yesterday.getDate() - 1); // 减去一天得到昨天的日期
        let zt = this.formatDate(yesterday);
        this.queryParams.startCreateTime = zt + " 00:00:00"
        this.queryParams.endCreateTime = zt + " 23:59:59"
      }else if (item === 2){
        let jt = this.formatDate(date);
        this.queryParams.startCreateTime = jt + " 00:00:00"
        this.queryParams.endCreateTime = jt + " 23:59:59"
      }else if (item === 3) {
        const tomorrow = new Date(date);
        tomorrow.setDate(tomorrow.getDate() + 1); // 加上一天得到明天的日期
        let mt = this.formatDate(tomorrow);
        this.queryParams.startCreateTime = mt + " 00:00:00"
        this.queryParams.endCreateTime = mt + " 23:59:59"
      }
      this.getList()
    },
    formatDate(date) {
      const year = date.getFullYear();
      const month = String(date.getMonth() + 1).padStart(2, '0'); // 月份从0开始，所以加1
      const day = String(date.getDate()).padStart(2, '0');
      return `${year}-${month}-${day}`;
    }
  }
};
</script>
